<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <title>Retina Dashboard</title>
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <meta name="robots" content="" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" href="/static/css/style.css" media="all" />
    <!--[if IE]><link rel="stylesheet" href="/static/css/ie.css" media="all" /><![endif]-->
    <!--[if lt IE 9]><link rel="stylesheet" href="/static/css/lt-ie-9.css" media="all" /><![endif]-->
    <!--<script src="/static/js/jquery.timer.js"></script>-->
    <script src="/static/js/jquery-1.10.1.min.js"></script>
    <script src="/static/js/jquery.tablesorter.min.js"></script>

</head>
<body class="login">
<section>
    <h1><strong>Retina</strong> Dashboard</h1>
    <h2 class="error">{{.error}}</h2>
    <form id="login_form" method="post" action="/admin/login">
        <input type="text" name="Tel" id = "Tel" value="请输入你的手机号" />
        <input name="UserPw" id = "pw" type="password" />
        <div>
            <input value="验证码" id="verify-code" type="text" />
            <button id="msg_btn" >验证码</button>
        </div>
        <button type="submit" class="blue" id="login-btn">登陆</button>
    </form>
    <p><a href="#">Forgot your password?</a></p>
</section>


<script type="text/javascript">
    $(function(){
        $('input').each(function() {
            var default_value = this.value;

            $(this).focus(function(){
                if(this.value == default_value) {
                    this.value = '';
                }
            });

            $(this).blur(function(){
                if(this.value == '') {
                    this.value = default_value;
                }
            });

        });
    });
</script>

<script type="text/javascript">
$(function(){
   /* $('body').everyTime('10s',function(){
            //alert("sss");
    });*/
    var count_time = 0;
    function CountDown(){
        count_time += 1;
        //alert(count_time);
        if(count_time>=59){
            //alert(count_time);
            $("#msg_btn").removeAttr("disabled");
             $("#Tel").removeAttr("disabled");
            $("#msg_btn").text("验证码")
            count_time = 0;
            return;
        }else{
            $("#msg_btn").text(60-count_time)
            setTimeout(CountDown,1000);
        }
    }
    $("#msg_btn").click(function(){
        if(!$("#Tel").val().match(/^(((13[0-9]{1})|159|153|185|186|177)+\d{8})$/)){
            alert("输入的手机号有误");
            return false;
        }
        $("#msg_btn").attr("disabled","disabled");
        CountDown();
        var tel = $("#Tel").val();
        $.post('http://'+window.location.host+'/admin/api/get_verify_code/',{'Tel':tel},function(data){
				console.log(data)
				if(data.RespCode == 200){

				}else{
				    alert(data.Msg);
				}
                return false
			});
        return false;
    });
    $("#login-btn").click(function(){
        alert($("#login-btn").text());
        var tel = $("#Tel").val();
        var pw = $("#pw").val();
        var verify_code = $("#verify-code").val();
        var verify_code_status = false
        $.post('http://'+window.location.host+'/admin/api/check_verify_code/',{'Tel':tel,'VerifyCode':verify_code},function(data){
				console.log(data)
				if(data.RespCode == 200){
                    /*$.post('http://'+window.location.host+'/admin/login',{'Tel':tel,'UserPw':pw},function(data){
                        console.log(data)
                    });*/
                    $("#login_form").submit();
                   }else{
                        alert(data.Msg);
                   }
                return false
			});


    });
});
</script>
</body>
</html>